package com.huowei.htzy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.huowei.htzy.R;
import com.huowei.htzy.modle.Goods;
import com.huowei.htzy.util.GlideUtil;
import com.huowei.htzy.util.ViewHolderUtil;

import java.util.List;

/**
 * Created by huowei on 2016/10/12.
 */

public class GoodAdapter extends BaseAdapter {
    private List<Goods.ItemBean> goods;
    private Context context;

    public GoodAdapter(List<Goods.ItemBean> goods, Context context) {
        this.goods = goods;
        this.context = context;
    }

    @Override
    public int getCount() {
        return goods.size();
    }

    @Override
    public Object getItem(int position) {
        return goods.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.good_adapter_item,null);
        }
        ImageView imageViewImagePic01 = ViewHolderUtil.get(convertView,R.id.ImageViewImagePic01);
        TextView textViewTitle = ViewHolderUtil.get(convertView,R.id.TextViewTitle);
        TextView textViewPrice = ViewHolderUtil.get(convertView,R.id.TextViewPrice);
        TextView textViewGuige = ViewHolderUtil.get(convertView,R.id.TextViewGuige);
        TextView textViewFactory = ViewHolderUtil.get(convertView,R.id.TextViewFactory);
        Goods.ItemBean itemBean = goods.get(position);
        GlideUtil.setRequest(context,itemBean.getGoods_image(),imageViewImagePic01);
        textViewTitle.setText(itemBean.getGoods_name());
        textViewPrice.setText(itemBean.getGoods_promotion_price());
        textViewFactory.setText(itemBean.getProduct_company());
        textViewGuige.setText(itemBean.getDrug_spec());
        return convertView;
    }
}
